#define _CRT_SECURE_NO_WARNINGS 1

#include"SList.h"

void SLTPrint(SLTNode* phead) {
	SLTNode* pcur = phead;
	while (pcur) {
		printf("%d->", pcur->data);
		pcur = pcur->next;
	}
	printf("NULL\n");
}

SLTNode* SLTBuyNode(SLTDataType x) {
	SLTNode* pnewnode = (SLTNode*)malloc(sizeof(SLTNode));
	if (!pnewnode) {
		perror("malloc");
		exit(1);
	}
	pnewnode->data = x;
	pnewnode->next = NULL;
	return pnewnode;
}

void SLTPushBack(SLTNode** pphead, SLTDataType x) {
	assert(pphead);

	SLTNode* pnewnode = SLTBuyNode(x);

	if (!*pphead) {
		*pphead = pnewnode;
		return;
	}

	SLTNode* ptail = *pphead;
	while (ptail->next) {
		ptail = ptail->next;
	}
	ptail->next = pnewnode;
}

void SLTPushFront(SLTNode** pphead, SLTDataType x) {
	assert(pphead);

	SLTNode* pnewnode = SLTBuyNode(x);

	pnewnode->next = *pphead;
	*pphead = pnewnode;
}